
import '../../http/Url.dart';
import '../../http/http_manager.dart';
import '../../model/base_viewmodel.dart';
import '../../model/discovery/topic_detail_model.dart';
import '../../utils/toast_util.dart';
import '../../widget/loading_state_widget.dart';

class TopicDetailViewModel extends BaseViewModel {
  TopicDetailModel topicDetailModel = TopicDetailModel();
  List<TopicDetailItemData> itemList = [];
  final int _id;

  TopicDetailViewModel(this._id);

  @override
  void refresh() {
    HttpManager.requestData('${Url.topicsDetailUrl}$_id').then((res) {
      topicDetailModel = TopicDetailModel.fromJson(res);
      itemList = topicDetailModel.itemList??[];
      viewState = ViewState.done;
    }).catchError((e) {
      AppToast.showError(e.toString());
      viewState = ViewState.error;
    }).whenComplete(() => notifyListeners());
  }
}